﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using BangleCMS.DBUtility;//Please add references
namespace BangleCMS.DAL
{
	/// <summary>
	/// 数据访问类:view_modular_userDAL
	/// </summary>
	public partial class view_modular_userDAL
	{
		public view_modular_userDAL()
		{}
		#region  Method



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(BangleCMS.Model.view_modular_user model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into view_modular_user(");
			strSql.Append("ModularId,ModularName,ModularCode,OrderNo,CreateUser,CreateUserName,CreateDate,UpdateUser,UpdateDate,Valid)");
			strSql.Append(" values (");
			strSql.Append("@ModularId,@ModularName,@ModularCode,@OrderNo,@CreateUser,@CreateUserName,@CreateDate,@UpdateUser,@UpdateDate,@Valid)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@ModularId", MySqlDbType.Int32,11),
					new MySqlParameter("@ModularName", MySqlDbType.VarChar,100),
					new MySqlParameter("@ModularCode", MySqlDbType.VarChar,50),
					new MySqlParameter("@OrderNo", MySqlDbType.Int32,11),
					new MySqlParameter("@CreateUser", MySqlDbType.Int32,11),
					new MySqlParameter("@CreateUserName", MySqlDbType.VarChar,100),
					new MySqlParameter("@CreateDate", MySqlDbType.DateTime),
					new MySqlParameter("@UpdateUser", MySqlDbType.Int32,11),
					new MySqlParameter("@UpdateDate", MySqlDbType.DateTime),
					new MySqlParameter("@Valid", MySqlDbType.Int32,11)};
			parameters[0].Value = model.ModularId;
			parameters[1].Value = model.ModularName;
			parameters[2].Value = model.ModularCode;
			parameters[3].Value = model.OrderNo;
			parameters[4].Value = model.CreateUser;
			parameters[5].Value = model.CreateUserName;
			parameters[6].Value = model.CreateDate;
			parameters[7].Value = model.UpdateUser;
			parameters[8].Value = model.UpdateDate;
			parameters[9].Value = model.Valid;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(BangleCMS.Model.view_modular_user model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update view_modular_user set ");
			strSql.Append("ModularId=@ModularId,");
			strSql.Append("ModularName=@ModularName,");
			strSql.Append("ModularCode=@ModularCode,");
			strSql.Append("OrderNo=@OrderNo,");
			strSql.Append("CreateUser=@CreateUser,");
			strSql.Append("CreateUserName=@CreateUserName,");
			strSql.Append("CreateDate=@CreateDate,");
			strSql.Append("UpdateUser=@UpdateUser,");
			strSql.Append("UpdateDate=@UpdateDate,");
			strSql.Append("Valid=@Valid");
			strSql.Append(" where ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@ModularId", MySqlDbType.Int32,11),
					new MySqlParameter("@ModularName", MySqlDbType.VarChar,100),
					new MySqlParameter("@ModularCode", MySqlDbType.VarChar,50),
					new MySqlParameter("@OrderNo", MySqlDbType.Int32,11),
					new MySqlParameter("@CreateUser", MySqlDbType.Int32,11),
					new MySqlParameter("@CreateUserName", MySqlDbType.VarChar,100),
					new MySqlParameter("@CreateDate", MySqlDbType.DateTime),
					new MySqlParameter("@UpdateUser", MySqlDbType.Int32,11),
					new MySqlParameter("@UpdateDate", MySqlDbType.DateTime),
					new MySqlParameter("@Valid", MySqlDbType.Int32,11)};
			parameters[0].Value = model.ModularId;
			parameters[1].Value = model.ModularName;
			parameters[2].Value = model.ModularCode;
			parameters[3].Value = model.OrderNo;
			parameters[4].Value = model.CreateUser;
			parameters[5].Value = model.CreateUserName;
			parameters[6].Value = model.CreateDate;
			parameters[7].Value = model.UpdateUser;
			parameters[8].Value = model.UpdateDate;
			parameters[9].Value = model.Valid;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from view_modular_user ");
			strSql.Append(" where ");
			MySqlParameter[] parameters = {
			};

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public BangleCMS.Model.view_modular_user GetModel()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ModularId,ModularName,ModularCode,OrderNo,CreateUser,CreateUserName,CreateDate,UpdateUser,UpdateDate,Valid from view_modular_user ");
			strSql.Append(" where ");
			MySqlParameter[] parameters = {
			};

			BangleCMS.Model.view_modular_user model=new BangleCMS.Model.view_modular_user();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ModularId"]!=null && ds.Tables[0].Rows[0]["ModularId"].ToString()!="")
				{
					model.ModularId=int.Parse(ds.Tables[0].Rows[0]["ModularId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ModularName"]!=null && ds.Tables[0].Rows[0]["ModularName"].ToString()!="")
				{
					model.ModularName=ds.Tables[0].Rows[0]["ModularName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ModularCode"]!=null && ds.Tables[0].Rows[0]["ModularCode"].ToString()!="")
				{
					model.ModularCode=ds.Tables[0].Rows[0]["ModularCode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["OrderNo"]!=null && ds.Tables[0].Rows[0]["OrderNo"].ToString()!="")
				{
					model.OrderNo=int.Parse(ds.Tables[0].Rows[0]["OrderNo"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CreateUser"]!=null && ds.Tables[0].Rows[0]["CreateUser"].ToString()!="")
				{
					model.CreateUser=int.Parse(ds.Tables[0].Rows[0]["CreateUser"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CreateUserName"]!=null && ds.Tables[0].Rows[0]["CreateUserName"].ToString()!="")
				{
					model.CreateUserName=ds.Tables[0].Rows[0]["CreateUserName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CreateDate"]!=null && ds.Tables[0].Rows[0]["CreateDate"].ToString()!="")
				{
					model.CreateDate=DateTime.Parse(ds.Tables[0].Rows[0]["CreateDate"].ToString());
				}
				if(ds.Tables[0].Rows[0]["UpdateUser"]!=null && ds.Tables[0].Rows[0]["UpdateUser"].ToString()!="")
				{
					model.UpdateUser=int.Parse(ds.Tables[0].Rows[0]["UpdateUser"].ToString());
				}
				if(ds.Tables[0].Rows[0]["UpdateDate"]!=null && ds.Tables[0].Rows[0]["UpdateDate"].ToString()!="")
				{
					model.UpdateDate=DateTime.Parse(ds.Tables[0].Rows[0]["UpdateDate"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Valid"]!=null && ds.Tables[0].Rows[0]["Valid"].ToString()!="")
				{
					model.Valid=int.Parse(ds.Tables[0].Rows[0]["Valid"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ModularId,ModularName,ModularCode,OrderNo,CreateUser,CreateUserName,CreateDate,UpdateUser,UpdateDate,Valid ");
			strSql.Append(" FROM view_modular_user ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM view_modular_user ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T. desc");
			}
			strSql.Append(")AS Row, T.*  from view_modular_user T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "view_modular_user";
			parameters[1].Value = "";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

